package com.yunshang.shoppingmall.shopping.productApi.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunshang.shoppingmall.common.IndexProductUtil;

import com.yunshang.shoppingmall.common.WeinXinUtil;
import com.yunshang.shoppingmall.entity.*;
import com.yunshang.shoppingmall.service.*;
import com.yunshang.shoppingmall.service.User.UserRankService;
import com.yunshang.shoppingmall.service.impl.ProductApisServiceImpl;
import org.omg.PortableInterceptor.INACTIVE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.*;


/**
 * 商品首页
 */
@Controller
@RequestMapping("/wap")
public class ProductIndexController {

    @Autowired
    PannerService pannerService;

    @Autowired
    ProductApisService productApisService;

    @Autowired
    UserRankService userRankService;

    @Autowired
    ProductPriceService productPriceService;

    @Autowired
    SearchHistoryService searchHistoryService;

    @Autowired
    ProductADVService productADVService;

    @Autowired
    ProductService productService;

    @Autowired
    ProductGuiGeService productGuiGeService;

    @Autowired
    CartService cartService;
    @Autowired
    SysUserNoService sysUserNoService;
    @Autowired
    ProductGuigePriceService productGuigePriceService;
    @Autowired
    IndexProductService indexProductService;
    @Autowired
    ConfigService configService;
    ProductApisServiceImpl productApisServiceImpl = new ProductApisServiceImpl();
    PriceData priceData = null;

    Logger logger = LoggerFactory.getLogger(ProductIndexController.class);

    @RequestMapping("/productIndex")
    public ModelAndView productIndex(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        ModelAndView modelAndView = new ModelAndView("shoppingApi/product/index");
        HttpSession session = request.getSession();

        if (session.getAttribute("subscribe") != null) {
            System.out.println("subscribe:AAA");
            map.put("subscribe", 1);
        } else {
            map.put("subscribe", null);
        }

        //获取登录用户提成比
        //panner图
        int pannerActiveSign = 1;
        List<Panner> pannerList = pannerService.selectPanners(pannerActiveSign);

        //首页热卖广告图
        String advSgin = "30";
        List<ProductADV> advList = productADVService.selectProductADVBySign(advSgin);
        map.put("advList1", advList.get(0));
        map.put("advList2", advList.get(1));
        map.put("advList3", advList.get(2));
        map.put("advList4", advList.get(3));
        map.put("pannerLists", pannerList);
        UserNo userNo = (UserNo) request.getSession().getAttribute("userNo");
        int userNoId=0;
        if(userNo!=null){
            userNoId=userNo.getId();
        }
        modelAndView.addObject("userNoId",userNoId);
        return modelAndView;
    }


    @ResponseBody
    @RequestMapping("/getIndexData")
    public Map<String, Object> getIndexData(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        int userNoId = 0;
        int userRankId = 0;
        UserRank userRank = null;
        double commission = 0.00;
        double minyhPrice = 0.00;//最低优惠价格
        double fenXiangZhuan = 0.00;//分享赚
        double newUserCommission = 0.00;//新用户提成比
        double yhcommission = 0.00;
        double ykcommission = 0.00;
        int page = 0;
        int pageSize = 5;
        List commissionarr = new ArrayList();
        UserNo userNo = (UserNo) request.getSession().getAttribute("userNo");
        String pages = request.getParameter("page");

        if (pages != null && pages != "") {
            page = Integer.parseInt(pages);
        }

        System.out.println("page:" + page);
        if (userNo != null) {
            userNoId = userNo.getId();
            userRankId = userNo.getRank();
            userRank = userRankService.selectByPrimaryKey(userRankId);
            commission = userRank.getCommission();
            //新用户的提成比
            List<UserRank> userRankList = userRankService.selectUserRankList();

            //获取新用户的提成比
            for (int i = 0; i < userRankList.size(); i++) {
                commissionarr.add(userRankList.get(i).getCommission());
            }
            Collections.sort(commissionarr);
            newUserCommission = (double) commissionarr.get(0);
            if (commission <= newUserCommission) {
                newUserCommission = 0.00;
            }

        } else {
            //未登录
            List<UserRank> userRankList = userRankService.selectUserRankList();
            for (int i = 0; i < userRankList.size(); i++) {
                commissionarr.add(userRankList.get(i).getCommission());
            }
            Collections.sort(commissionarr);

            //分享赚
            commission = (double) commissionarr.get(0);
            newUserCommission = (double) commissionarr.get(0);
        }

        //加载零售专区数据
        IndexProduct indexProduct = new IndexProduct();
        indexProduct.setActiveSign(4);
        indexProduct.setProductUpState("Y");
        PageHelper.startPage(page, pageSize);
        List<IndexProduct> indexProductList = indexProductService.selectProductListByActiveSignAndProductUpState(indexProduct);
        PageInfo<IndexProduct> pageInfo=new PageInfo<>(indexProductList);

        List<IndexProduct> indexProductList1 = new ArrayList<>();

        //分享赚以及优惠后最低
        IndexProduct indexProductData = null;
        for (int i = 0; i < indexProductList.size(); i++) {
            indexProductData = indexProductList.get(i);


            fenXiangZhuan = IndexProductUtil.getFenXiangZhuan(indexProductData, commission, newUserCommission);
            switch (userRankId) {
                case 16:   //优惠后最低
//
                    indexProductData.setMinyhPrice(0.00);
                    break;
                case 17:
                    minyhPrice = IndexProductUtil.getMinyhPrice(indexProductData, commission);
                    indexProductData.setMinyhPrice(minyhPrice);
                    indexProductData.setYzDianzhu(0);
                    break;

                case 18:
                    minyhPrice = IndexProductUtil.getMinyhPrice(indexProductData, commission);
                    indexProductData.setMinyhPrice(minyhPrice);
                    indexProductData.setYzDianzhu(0);
                    break;

                case 19:
                    indexProductData.setMinyhPrice(0.00);
                    indexProductData.setYzDianzhu(0);
                    break;

                case 20:
                    indexProductData.setMinyhPrice(0.00);
                    indexProductData.setYzDianzhu(0);
                    break;

                case 21:
                    minyhPrice = IndexProductUtil.getMinyhPrice(indexProductData, commission);
                    indexProductData.setMinyhPrice(minyhPrice);
                    indexProductData.setYzDianzhu(0);
                    break;

                case 22:
                    minyhPrice = IndexProductUtil.getMinyhPrice(indexProductData, commission);
                    indexProductData.setMinyhPrice(minyhPrice);
                    indexProductData.setYzDianzhu(0);
                    break;
                default:
                    indexProductData.setMinyhPrice(0.00);
                    indexProductData.setYzDianzhu(0);
                    break;

            }

            indexProductData.setFenXiangZhuan(fenXiangZhuan);

            indexProductList1.add(indexProductData);
        }

        Config config = configService.selectByPrimaryKey(1);
        map.put("indexProductList", indexProductList1);
        map.put("userNo",userNo);
        map.put("config", config);
        map.put("pageCount",pageInfo.getTotal()/pageInfo.getPageSize()==0?0:pageInfo.getTotal()/pageInfo.getPageSize()+1);
        return map;
    }


    /*分享*/
    @ResponseBody
    @RequestMapping("/indexShare")
    public Map<String, Object> IndexShare(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        //  String strUrl = "www.ycsqd.com" + request.getContextPath()+ request.getServletPath()+ "?" + (request.getQueryString()); //请求页面或其他地址
//   String strUrl="http://localhost:8092/wap/productIndex";
        String strUrl = request.getParameter("url");
        //参数
        String hostUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        WeiXinEntity wx = WeinXinUtil.getWinXinEntity(strUrl);

        map.put("wx", wx);
        //当前域名-用于分享出去的地址
        map.put("hostUrl", hostUrl);
        return map;
    }

    //跳转到搜索页面
    @RequestMapping("/search")
    public ModelAndView search() {
        Map<String, Object> map = new HashMap<>();
        List<SearchHistory> searchHistoryList = new ArrayList<>();
        ModelAndView modelAndView = new ModelAndView("shoppingApi/product/search");
        return modelAndView;
    }

    //跳转到搜索结果页面
    @RequestMapping("/searchResult")
    public ModelAndView searchResult(HttpServletRequest request, @RequestParam("productName") String productName) {

        ProductHot productHot = null;
        List<ProductHot> productHotList = new ArrayList<>();
        List<ProductPrice> productPriceList = new ArrayList<>();

        List<Integer> prodouctIdList = new ArrayList<>();//商品id
        List<ProductApis> productApisLists = new ArrayList<>();
        ProductApis productApis = null;

        double minProPrice = 0.00;
        double maxProPrice = 0.00;
        int YzDianzhu = 0;
        double minyhPrice = 0.00;
        double proPrice = 0.00;
        double[] proPriceArr = new double[20];

        double opratorCost = 0.00;
        double[] opratorCostArr = new double[20];

        double productCost = 0.00;
        double[] productCostArr = new double[20];

        double procoupon = 0.00;
        double[] procouponArr = new double[20];

        double YZDianzhus = 0.00;

        double commission = 0.00;
        double dzcommission = 0.00;
        double hycommission = 0.00;

        double[] minyhPrices = new double[20];
        double minyhPricess = 0.00;
        String minyhPriceformat = "";

        double fenXiangZhuan = 0.00;


        Map<String, Object> map = new HashMap<>();
        List<ProductApis> productApisList = new ArrayList<>();

        ModelAndView modelAndView = new ModelAndView("shoppingApi/product/searchResult");
        productApisList = productApisService.selectProductByProductName(productName);
        for (int i = 0; i < productApisList.size(); i++) {
            productHot = new ProductHot();
            productHot.setProId(productApisList.get(i).getProductId());
            productHot.setProDesc(productApisList.get(i).getProductDesc());
            productHot.setProImg(productApisList.get(i).getProImg());
            //根据productId查询商品价格
            productPriceList = productPriceService.selectProductPriceByProId(productApisList.get(i).getProductId());
            for (int j = 0; j < productPriceList.size(); j++) {
                if (prodouctIdList != null && productPriceList.size() > 0) {
                    if (productPriceList.get(j) != null) {
                        try {
                            YzDianzhu = productPriceList.get(j).getYzDianzhu();
                        } catch (Exception e) {
                            return modelAndView;
                        }
                    }
                    YZDianzhus = (double) YzDianzhu;
                    BigDecimal coupon = productPriceList.get(j).getCoupon();
                    procoupon = coupon.doubleValue();
                    BigDecimal productCost1 = productPriceList.get(j).getProductCost();
                    productCost = productCost1.doubleValue();
                    BigDecimal opratorCost1 = productPriceList.get(j).getOpratorCost();
                    opratorCost = opratorCost1.doubleValue();
                    BigDecimal proPrice1 = productPriceList.get(j).getProPrice();//商城价
                    proPrice = proPrice1.doubleValue();
                    productHot.setProductPrice(proPrice);
                    //最低优惠价格
                    minyhPrice = productApisServiceImpl.getMinyhPrice(proPrice, productCost, opratorCost, procoupon, YZDianzhus, commission);
                    productHot.setMinYHPrice(minProPrice);
                    minyhPrices[j] = minyhPrice;
                    //分享赚
                    fenXiangZhuan = productApisServiceImpl.getFenXiangZhuan(proPrice, productCost, opratorCost, procoupon, YZDianzhus, commission, hycommission);
                    productHot.setFenXiangZhuan(fenXiangZhuan);

                }


            }
            productHotList.add(i, productHot);

            map.put("productHotList", productHotList);

            modelAndView.addObject("map", map);

        }

        return modelAndView;
    }


    /*零售专区*/
    @ResponseBody
    @RequestMapping(value = "/getProductIndex", method = RequestMethod.POST)
    public Map<String, Object> getProductIndex(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        int page = 1;
        int limit = 5;
        PageHelper.startPage(page, limit);
        List<PriceData> priceDataList = getProductDuiHuanData(request);
//        PageInfo<PriceData> pageInfo=new PageInfo<>(priceDataList);
        map.put("priceDataList", priceDataList);
        return map;
    }

    /*兑换专区*/
    @RequestMapping("/openDuiHuan")
    public ModelAndView openDuiHuan(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        ModelAndView modelAndView = new ModelAndView("shoppingApi/product/duihuan");
        IndexProduct indexProduct = new IndexProduct();
        indexProduct.setActiveSign(5);
        indexProduct.setProductUpState("Y");
        List<IndexProduct> indexProductList = indexProductService.selectProductListByActiveSignAndProductUpState(indexProduct);
        map.put("indexProductList", indexProductList);

        modelAndView.addObject("map", map);
        return modelAndView;
    }

    /*滚动加载时候获取加载的数据*/
//    @ResponseBody
//    @RequestMapping(value = "/getLoadData", method = RequestMethod.POST)
//    public Map<String, Object> getLoadData(HttpServletRequest request) {
//        Map<String, Object> map = new HashMap<>();
//        List<PriceData> priceDataList = getProductDuiHuanData(request);
//        map.put("priceDataList", priceDataList);
//        return map;
//    }


    /*体验专区*/
    @RequestMapping("/openTiYan")
    public ModelAndView openTiYan(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        ModelAndView modelAndView = new ModelAndView("shoppingApi/product/tiyan");
        IndexProduct indexProduct = new IndexProduct();
        indexProduct.setProductUpState("Y");
        indexProduct.setActiveSign(3);
        List<IndexProduct> indexProductList = indexProductService.selectProductListByActiveSignAndProductUpState(indexProduct);
        map.put("indexProductList", indexProductList);
        modelAndView.addObject("map", map);
        return modelAndView;
    }


    /*活动专区*/
    @RequestMapping("/openHuoDong")
    public ModelAndView openHuoDong(HttpServletRequest request) {

        ModelAndView modelAndView = new ModelAndView("shoppingApi/product/huodong");

//        getActiveData(request, map, modelAndView);
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping("/getActiveData")
    public Map<String, Object> getActiveData(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();

        String pages = request.getParameter("page");
        int page = 0;
        int pageSize = 5;
        if (pages != null && pages != "") {
            page = Integer.parseInt(pages);
        }
        IndexProduct indexProduct = new IndexProduct();
        indexProduct.setProductUpState("Y");
        int signs = 7;
        indexProduct.setActiveSign(signs);

        //查询该专区的商品
        PageHelper.startPage(page, pageSize);
        List<IndexProduct> indexProductList = indexProductService.selectProductListByActiveSignAndProductUpState(indexProduct);
        map.put("indexProductList", indexProductList);
        return map;
    }


    /*获取首页加载数据*/
    public List<PriceData> getProductDuiHuanData(HttpServletRequest request) {
        double commission = 0.00;
        Map<String, Object> map = new HashMap<>();
        int pageNums = 0;
        int sign = 0;
        String pageNum = request.getParameter("pageNum");
        String signs = request.getParameter("sign");
        if (signs != "" && signs != null) {
            sign = Integer.parseInt(signs);
        }
        if (pageNum != "" && pageNum != null) {
            System.out.println("pageNum==" + pageNum);
            pageNums = Integer.parseInt(pageNum);

        } else {
            pageNums = 0;
        }
        HttpSession session = request.getSession();
        map = getCommission(session); //用户等级提成比

        System.out.println("---------------------->commision:" + commission);
        //零售区商品
        //根据productSign活动标志查询商品
        List<PriceData> proPriceList = getProductData(0, map, sign);

        return proPriceList;
    }


    /**
     * 微信分享
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/weixinShare")
    public Map<String, Object> weixinShare(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        //微信分享
        String strUrl = "http://weixin.gzqjyc.com"
                + request.getContextPath()   //项目名称
                + request.getServletPath();  //请求页面或其他地址
//                + "?" + (request.getQueryString()); //参数

        WeiXinEntity wx = WeinXinUtil.getWinXinEntity(strUrl);
        //将wx的信息返回给页面
//        request.setAttribute("wx", wx);
        map.put("wx", wx);
        return map;
    }


    /*商品数据展示方法*/
    public List getProductData(int pageNum, Map<String, Object> map, int sign) {
        int pageSize = 20;

        PriceData priceData = null;
        double minLiRun = 0.00;   //最低利润值
        double minYHPrice = 0.00;//实际支付，最低优惠后价格
        double hyJieSheng = 0.00; //会员节省
        double fenXiangZhuan = 0.00;//分享赚
        List proPriceList = new ArrayList();
        double commission = 0.00;
        double recommendCommission = 0.00;
//        PageHelper.startPage(pageNum,pageSize);
        List<Product> productList = productService.selectProductByActiveSign(sign);//根据专区标志查询所有商品
        for (int i = 0; i < productList.size(); i++) {
            priceData = new PriceData();
            int productId = productList.get(i).getProductId();
            priceData.setProductId(productId);
            priceData.setProImg(productList.get(i).getProImg());
            priceData.setProductDesc(productList.get(i).getProductDesc());

            //查询规格id
            List<ProductGuiGe> productGuiGeList = productGuiGeService.selectGuigeListByProductId(productId);
            if (productGuiGeList.size() != 0) {
                //获取第一个规格商品作为展示
                int guigeId = productGuiGeList.get(0).getGuigeId();
                //根据规格id查询该规格对应的价格
                ProductPrice productPrice = productPriceService.selectProductPriceByGuigeId(guigeId);
                //最低利润值:商城价-购物券-折扣券-运营成本-商品成本
                if (productPrice != null) {
                    if (productPrice.getProPrice() != null && productPrice.getCoupon() != null && productPrice.getYzDianzhu() != null && productPrice.getOpratorCost() != null && productPrice.getProductCost() != null) {
                        minLiRun = productPrice.getProPrice().doubleValue() - productPrice.getCoupon().doubleValue() - productPrice.getYzDianzhu().doubleValue() - productPrice.getOpratorCost().doubleValue() - productPrice.getProductCost().doubleValue();
                        priceData.setMinLiRun(minLiRun);
                    }
                    //商城价格
                    if (productPrice.getProPrice() != null) {
                        priceData.setProPrice(productPrice.getProPrice().doubleValue());
                    }
                    //会员节省

                    commission = (double) map.get("commission");
                    hyJieSheng = minLiRun * commission / 100;
                    priceData.setHyJieSheng(hyJieSheng);
                    //优惠后最低价:商城价-购物券-折扣券-会员节省
                    if (productPrice.getProPrice() != null && productPrice.getCoupon() != null && productPrice.getYzDianzhu() != null) {
                        minYHPrice = productPrice.getProPrice().doubleValue() - productPrice.getCoupon().doubleValue() - productPrice.getYzDianzhu() - hyJieSheng;
                        priceData.setMinYHPrice(minYHPrice);
                    }

                    //分享赚
                    recommendCommission = (double) map.get("recommendCommission");
                    if (recommendCommission >= commission) {
                        fenXiangZhuan = minLiRun * (recommendCommission - commission) / 100;
                    } else {
                        fenXiangZhuan = 0.00;
                    }
                    priceData.setFenXiangZhuan(fenXiangZhuan);
                    if (priceData != null) {
                        proPriceList.add(priceData);
                    }
                } else {
                    //当按照规格ID查询时候，价格为null时候，就按照产品ID来查询价格
                    ProductPrice productPrice1 = productPriceService.selectPriceByProductId(productId);
                    if (productPrice1 != null) {

                        if (productPrice1.getProPrice() != null && productPrice1.getCoupon() != null && productPrice1.getYzDianzhu() != null && productPrice1.getOpratorCost() != null && productPrice1.getProductCost() != null) {
                            minLiRun = productPrice1.getProPrice().doubleValue() - productPrice1.getCoupon().doubleValue() - productPrice1.getYzDianzhu().doubleValue() - productPrice1.getOpratorCost().doubleValue() - productPrice1.getProductCost().doubleValue();
                            priceData.setMinLiRun(minLiRun);
                        }
                        //商城价格
                        if (productPrice1.getProPrice() != null) {
                            priceData.setProPrice(productPrice1.getProPrice().doubleValue());
                        }
                        //会员节省
                        commission = (double) map.get("commission");
                        hyJieSheng = minLiRun * commission / 100;
                        priceData.setHyJieSheng(hyJieSheng);
                        //优惠后最低价:商城价-购物券-折扣券-会员节省
                        if (productPrice1.getProPrice() != null && productPrice1.getCoupon() != null && productPrice1.getYzDianzhu() != null) {
                            minYHPrice = productPrice1.getProPrice().doubleValue() - productPrice1.getCoupon().doubleValue() - productPrice1.getYzDianzhu() - hyJieSheng;
                            priceData.setMinYHPrice(minYHPrice);
                        }

                        //分享赚
                        recommendCommission = (double) map.get(map.get("recommendCommission"));
                        fenXiangZhuan = minLiRun * (recommendCommission - commission) / 100;
                        priceData.setFenXiangZhuan(fenXiangZhuan);
                        if (priceData != null) {
                            proPriceList.add(priceData);
                        }

                    }

                }
            }

        }
        return proPriceList;
    }

    /*获取用户登录*/
    public Map<String, Object> getCommission(HttpSession session) {
        Map<String, Object> map = new HashMap<>();
        double commission = 0.00;
        double recommendCommission = 0.00;
        int reCommendUserNoId = 0;//推荐人ID
        UserNo recommendUserNo = null;
        int recommendRankId = 0;
        UserNo userNo = (UserNo) session.getAttribute("userNo");

        if (session != null && userNo != null) {
            int rankId = userNo.getRank();
            reCommendUserNoId = userNo.getRecommend();
            recommendUserNo = sysUserNoService.selectByPrimaryKey(reCommendUserNoId);
            if (recommendUserNo != null) {
                recommendRankId = recommendUserNo.getRank();
            }

            if (rankId != 0) {
                //根据userId查询用户等级和提成比
                UserRank userRank = userRankService.selectByPrimaryKey(rankId);
                if ("优质店主".equals(userRank.getRankname())) {
                    commission = userRank.getCommission();//提成比
                }
                if ("店主".equals(userRank.getRankname())) {
                    commission = userRank.getCommission();//提成比
                }
                if ("会员".equals(userRank.getRankname())) {
                    commission = userRank.getCommission();//提成比
                }
                if ("游客".equals(userRank.getRankname())) {
                    commission = userRank.getCommission();//提成比
                }
            }

            if (recommendRankId != 0) {
                //根据userId查询用户等级和提成比
                UserRank recommendUserRank = userRankService.selectByPrimaryKey(recommendRankId);
                if ("优质店主".equals(recommendUserRank.getRankname())) {
                    recommendCommission = recommendUserRank.getCommission();//提成比
                }
                if ("店主".equals(recommendUserRank.getRankname())) {
                    recommendCommission = recommendUserRank.getCommission();//提成比
                }
                if ("会员".equals(recommendUserRank.getRankname())) {
                    recommendCommission = recommendUserRank.getCommission();//提成比
                }
                if ("游客".equals(recommendUserRank.getRankname())) {
                    recommendCommission = recommendUserRank.getCommission();//提成比
                }
            }


        } else {
            List<UserRank> userRankList = userRankService.selectUserRankList();
            double[] userArr = new double[10];
            for (int i = 0; i < userRankList.size(); i++) {
                if (userRankList.get(i) != null) {
                    userArr[i] = userRankList.get(i).getCommission();
                } else {
                    break;
                }

            }
            Arrays.sort(userArr);
            recommendCommission = userArr[2];
            commission = userArr[1];
        }

        map.put("commission", commission);
        map.put("recommendCommission", recommendCommission);
        return map;
    }


    /*根据用户Id查询其购物车的商品数量*/
    @ResponseBody
    @RequestMapping("/getCartProCountByUserId")
    public int getCartProCountByUserId(HttpServletRequest request) {
        int proCount = 0;
        HttpSession session = request.getSession();
        if (session != null) {
            UserNo userNo = (UserNo) session.getAttribute("userNo");
            if (userNo != null) {
                int userId = userNo.getId();
                proCount = cartService.selectCartProListByUserId(userId);
            } else {
                proCount = 0;
            }
        }
        return proCount;
    }

}
